package com.huidao.servlet.menu;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.huidao.entity.Menu;
import com.huidao.service.MenuService;
import com.huidao.service.MenuServiceImpl;


public class GetListMenuServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       

    public GetListMenuServlet() {
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		int currentPage = 1;
		if(request.getParameter("currentPage")!=null){
			currentPage = Integer.parseInt(request.getParameter("currentPage"));
		}
		String namekey = request.getParameter("namekey");
		MenuService s = new MenuServiceImpl();
		int totalPage = s.getTotalPage(namekey);
		//当删除最后一页的唯一一条记录的时候
		if(currentPage>totalPage){
			currentPage = totalPage;
		}
		List<Menu> list = s.getListPage(currentPage,namekey);
		request.setAttribute("list", list);
		request.setAttribute("currentPage", currentPage);
		request.setAttribute("totalPage", totalPage);
		request.getRequestDispatcher("GetMenuList.jsp").forward(request, response);
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	this.doGet(request, response);
	}

}
